//
//  CZHeaderView.m
//  A01- 团购
//
//  Created by Rainy Zou on 15/11/23.
//  Copyright © 2015年 Rainy Zou. All rights reserved.
//

#import "CZHeaderView.h"

#define ICONW 355

@interface CZHeaderView()<UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIPageControl *pageControl;

@end

@implementation CZHeaderView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
+ (instancetype)headerView
{
    CZHeaderView *headerView = [[[NSBundle mainBundle] loadNibNamed:@"CZHeaderView" owner:nil options:nil] lastObject];
    return headerView;
}

- (void)awakeFromNib
{
    CGFloat iconW = ICONW;
    CGFloat iconH = 140;
    for (int i=0; i<5; i++) {
        UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"ad_0%d.png",i]]];
        [self.scrollView addSubview:imageView];
        imageView.frame = CGRectMake(i*iconW, 0, iconW, iconH);
        
    }
    
    self.scrollView.contentSize = CGSizeMake(5*iconW, 0);
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.delegate = self;
    self.scrollView.pagingEnabled = YES;
    self.pageControl.enabled = NO;
    
}

#pragma mark 页翻滚
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    self.pageControl.currentPage = (int)(self.scrollView.contentOffset.x
                                         /ICONW);
}

@end
